@extends('PShop::modal')
@push('styles')
    <link href="{{asset(config('view.plugin').'/layui/css/layui.css')}}" rel="stylesheet">
@endpush
@section('content')
    <div class="am-padding-top">
        <form class="am-form am-form-horizontal" action="{{url()->current()}}" method="post">
            {{csrf_field()}}
            <div class="am-form-group">
                <label class="am-u-md-2 am-u-lg-2 am-padding-right-0 am-form-label">所在地址:</label>
                <div class="am-u-md-10 am-u-lg-10">
                    <div class="layui-form layui-form-pane">
                        <div class="layui-form-item post-area" lay-filter="post-area"></div>
                    </div>
                </div>
            </div>
            <div class="am-form-group">
                <label class="am-u-md-2 am-u-lg-2 am-padding-right-0 am-form-label">详细地址:</label>
                <div class="am-u-md-10 am-u-lg-10">
                    <textarea name="address" rows="5">{{$address->address ?? ''}}</textarea>
                </div>
            </div>
            <div class="am-form-group am-inline-block am-u-md-6">
                <label class="am-u-md-4 am-u-lg-4 am-padding-right-0 am-form-label">收货人:</label>
                <div class="am-u-md-8 am-u-lg-8 am-padding-left-sm am-padding-right-0">
                    <input type="text" name="name" value="{{$address->consignee ?? $info->real_name}}">
                </div>
            </div>
            <div class="am-form-group am-inline-block am-u-md-6">
                <label class="am-u-md-4 am-u-lg-4 am-padding-right-0 am-form-label">联系方式:</label>
                <div class="am-u-md-8 am-padding-right-0">
                    <input type="text" name="phone" value="{{$address->phone ?? $info->user_phone}}">
                </div>
            </div>
            <div class="clear"></div>
            <div class="am-form-group am-margin-top">
                <div class="am-u-md-offset-2 am-u-lg-offset-2 am-u-md-10 am-u-lg-10">
                    <div class="am-u-md-4 am-u-lg-4 am-padding-right-0 am-padding-top-xs am-padding-bottom-xs">
                        <label class="am-checkbox am-danger am-padding-top-0">
                            <input type="checkbox" name="is_default" {{(isset($address->is_default)&&$address->is_default==1)?'checked':''}} value="1" data-am-ucheck> 默认地址
                        </label>
                    </div>
                    <div class="am-u-md-8 am-u-lg-8 am-padding-left-0 am-text-right">
                        <div class="am-inline-block am-margin-right">
                            <input type="button" class="am-btn am-btn-danger am-radius save-address" value="确定" />
                        </div>
                        <div class="am-inline-block">
                            <input type="button" class="am-btn am-btn-default am-radius" value="取消"
                                   onclick="var index = parent.layer.getFrameIndex(window.name); parent.layer.close(index);"
                            />
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>

@endsection
@push('scripts')
    <script src="{{asset(config('view.plugin').'/layui/layui.js')}}"></script>
    <script>
        layui.use(['interact'], function(){
            var selected = "{{$address->area ?? ''}}";
            if(selected !=''){
                selected = selected.split(',')
            }else{
                selected = [3,37,38];
            }
            $.get("{{route('f_Home_getArea')}}",function (response) {
                var interact = layui.interact;
                interact.render({
                    elem : '.post-area',
                    data : response,
                    name : 'city',
                    selected:selected,
                    hint : ['请选择省份','请选择城市','请选择县/区'],
                });
            });

            $('.save-address').on('click',function () {
                var elem = $(this).parents('form');
                shopAjax({
                    url:elem.attr('action'),
                    data:elem.serialize(),
                    callback:function (response) {
                        if(response.status==1){
                            layer.msg('添加成功');
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            parent.location.reload();
                        }else{
                            layer.msg(response.msg);
                        }
                    }
                })
            });
        });
    </script>
@endpush